import { reqSearchGoodsInfo } from "@/api";
const state = {
  searchList: {},
};
const actions = {
  // 根据搜索参数获取商品列表数据
  async getSearchGoodsInfo({ commit }, params) {
    //请求数据
    let result = await reqSearchGoodsInfo(params);
    if (result.code === 200) {
      //200表示成功
      commit("GETGOODSLIST", result.data);
    } else {
      alert(result.message);
    }
  },
};
//getters相当于Vuex中的计算属性，可以精简需要映射的数据，并返回到state中
const getters = {
  goodsList(state) {
    return state.searchList.goodsList;
  },
  trademarkList(state) {
    return state.searchList.trademarkList;
  },
  attrsList(state) {
    return state.searchList.attrsList;
  },
  total(state){
    return state.searchList.total
  }
};
const mutations = {
  //相应请求回来的数据
  GETGOODSLIST(state, search) {
    //相应数据
    state.searchList = search;
  },
};

export default {
  namespaced: true, //名称唯一
  state,
  actions,
  getters,
  mutations,
};
